﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace STS.Common.Utils
{
    public static class STSUtils
    {
        public static T GetEnum<T>(object pNumber)
        {
            object lObj = Convert.ChangeType(pNumber, Enum.GetUnderlyingType(typeof(T)));

            if (Enum.IsDefined(typeof(T), lObj))
            {
                return (T)Enum.ToObject(typeof(T), lObj);
            }
            else
            {
                throw new ArgumentException(typeof(T).ToString() + " does not contain a value member = " + pNumber.ToString());
            }
        }

        public static string GetRelativePath(string rootPath, string absolutePath)
        {
            int idx = absolutePath.IndexOf(rootPath);
            if (idx != 0)
            {
                return null;
            }
            return absolutePath.Substring(idx + rootPath.Length);
        }

    }
}
